﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Backend;
using DBLayer;

namespace TestWCF
{
    [TestClass]
    public class TestDB
    {
        [TestMethod]
        public void SaveTaxiRequest()
        {
            
           
            int id = GetMax.GetMaxId() + 1;
           

            TaxiRequest taxiRequest = new TaxiRequest();
            System.Diagnostics.Debug.WriteLine("This is the fucking id: " + taxiRequest.Id);
            taxiRequest.Id = id;
            taxiRequest.Date = DateTime.Now.ToString();
            taxiRequest.Status = 1;
            taxiRequest.Address = "prinsensgade";
            taxiRequest.PhoneNr = "5929439";

            DBTaxiRequest dbTaxiRequest = new DBTaxiRequest();
            dbTaxiRequest.SaveTaxiRequest(taxiRequest);


            Assert.AreEqual(taxiRequest.PhoneNr, dbTaxiRequest.GetTaxiRequest(taxiRequest.Id).PhoneNr);


        }


        [TestMethod]
        public void GetTaxiRequestsByStatus()
        {
            DBTaxiRequest dbTaxiRequest = new DBTaxiRequest();
            int total = dbTaxiRequest.getTaxiRequestsByStatus(2).Count;
            TaxiRequest taxiRequest = new TaxiRequest();
            taxiRequest.Id = GetMax.GetMaxId() + 1;
            System.Diagnostics.Debug.WriteLine("This is the fucking id: " + taxiRequest.Id);
            taxiRequest.Status = 2;
            taxiRequest.PhoneNr = "91655396";
            taxiRequest.Address = "georgi";
            taxiRequest.Date = "2013-02-26 09:34:00.000";
            dbTaxiRequest.SaveTaxiRequest(taxiRequest);

            Assert.AreEqual(total + 1, dbTaxiRequest.getTaxiRequestsByStatus(2).Count);

        }



        [TestMethod]
        public void DeleteTaxiRequests()
        {
            DBTaxiRequest dbTaxiRequest = new DBTaxiRequest();
            int total = dbTaxiRequest.getTaxiRequestsByStatus(2).Count;
            TaxiRequest taxiRequest = new TaxiRequest();
            taxiRequest.Id = GetMax.GetMaxId() + 1;
            System.Diagnostics.Debug.WriteLine("This is the fucking id: " + taxiRequest.Id);
            taxiRequest.Status = 2;
            taxiRequest.PhoneNr = "91655396";
            taxiRequest.Address = "georgi";
            taxiRequest.Date = "2013-02-26 09:34:00.000";
            dbTaxiRequest.SaveTaxiRequest(taxiRequest);

            Assert.AreEqual(true, dbTaxiRequest.DeleteTaxiRequest(taxiRequest.Id));
            Assert.AreEqual(total, dbTaxiRequest.getTaxiRequestsByStatus(2).Count);


            for (int i = 30; i < 2000; i++)
            {
                dbTaxiRequest.DeleteTaxiRequest(i);
            }

        }


        [TestMethod]
        public void ChangeTaxiRequestStatus()
        {
            DBTaxiRequest dbTaxiRequest = new DBTaxiRequest();
            
            TaxiRequest taxiRequest = new TaxiRequest();
            taxiRequest.Id = GetMax.GetMaxId() + 1;
            System.Diagnostics.Debug.WriteLine("This is the fucking id: " + taxiRequest.Id);
            taxiRequest.Status = 2;
            taxiRequest.PhoneNr = "91655396";
            taxiRequest.Address = "georgi";
            taxiRequest.Date = "2013-02-26 09:34:00.000";
            dbTaxiRequest.SaveTaxiRequest(taxiRequest);

          Assert.AreEqual(true,  dbTaxiRequest.UpdateTaxiRequest(taxiRequest.Id, 3));
          Assert.AreEqual(3, dbTaxiRequest.GetTaxiRequest(taxiRequest.Id).Status);


        }

        [TestMethod]
        public void SaveUser()
        {
            Random rnd = new Random();
            int firstPart = rnd.Next(99, 1000);
            int secondPart = rnd.Next(99, 1000);
            int thirdPart = rnd.Next(99, 1000);
            User user = new User(firstPart.ToString()+secondPart.ToString()+thirdPart.ToString(), " Prinsensggade ");
            DBTaxiRequest dbTaxi = new DBTaxiRequest();
            Assert.AreEqual(true,dbTaxi.SaveUser(user));

        }


        [TestMethod]
        public void UpdateUser()
        {
            User user = new User(" 91 65 53 65", " Nibevej");
            DBTaxiRequest dbTaxi = new DBTaxiRequest();
            Assert.AreEqual(true, dbTaxi.UpdateUser(user));
        }


        [TestMethod]
        public void GetUser()
        {
            User user = new User(" 91 65 53 65", " Transalpina");
            DBTaxiRequest dbTaxi = new DBTaxiRequest();
            dbTaxi.UpdateUser(user);

            Assert.AreEqual(user.HomeAddress, dbTaxi.GetUser(user.PhoneNr).HomeAddress);
        }



        [TestMethod]
        public void ChangeTaxiRequestWithPlateNr()
        {
            DBTaxiRequest dbTaxiRequest = new DBTaxiRequest();

            TaxiRequest taxiRequest = new TaxiRequest();
            taxiRequest.Id = GetMax.GetMaxId() + 1;
            System.Diagnostics.Debug.WriteLine("This is the fucking id: " + taxiRequest.Id);
            taxiRequest.Status = 2;
            taxiRequest.PhoneNr = "91655396";
            taxiRequest.Address = "georgi";
            taxiRequest.Date = "2013-02-26 09:34:00.000";
            dbTaxiRequest.SaveTaxiRequest(taxiRequest);
    

            Assert.AreEqual(true, dbTaxiRequest.UpdateTaxiRequestWithPlateNr(taxiRequest.Id, "Halelele"));
            Assert.AreEqual("Halelele", dbTaxiRequest.GetTaxiRequest(taxiRequest.Id).PlateNr);


        }

        [TestMethod]
        public void ChangeTaxiRequestWithEstimatedTime()
        {
            DBTaxiRequest dbTaxiRequest = new DBTaxiRequest();

            TaxiRequest taxiRequest = new TaxiRequest();
            taxiRequest.Id = GetMax.GetMaxId() + 1;
            System.Diagnostics.Debug.WriteLine("This is the fucking id: " + taxiRequest.Id);
            taxiRequest.Status = 2;
            taxiRequest.PhoneNr = "91655396";
            taxiRequest.Address = "georgi";
            taxiRequest.Date = "2013-02-26 09:34:00.000";
            dbTaxiRequest.SaveTaxiRequest(taxiRequest);


            Assert.AreEqual(true, dbTaxiRequest.UpdateTaxiRequestWithEstimatedTime(taxiRequest.Id, "in 3 days"));
            Assert.AreEqual("in 3 days", dbTaxiRequest.GetTaxiRequest(taxiRequest.Id).EstimatedTime);


        }
    
    
            
    }
}
